package com.bringway.p2p.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bringway.framework.controller.JsonController;
import com.bringway.framework.util.RequestUtils;
import com.bringway.p2p.service.DkService;



/**
 * 
 * @author zhai
 * @version 创建时间：2015年12月14日 上午9:34:42
 * @功能：抽奖结果页面
 */


@Controller
@RequestMapping("/dkr")
public class DkController extends JsonController{

	@Autowired
	private DkService dkService;

	/**
	 * 
	 * @param request 获取请球的数据
	 * @param response 存储数据结果集
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping("/querydkr")
	public ModelAndView queryCjjgList(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		String ddh = RequestUtils.getStringParameter(request, "ddh");
		String maxdkje = RequestUtils.getStringParameter(request, "maxdkje");
		String mindkje = RequestUtils.getStringParameter(request, "mindkje");
		String state = RequestUtils.getStringParameter(request, "state");

		
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("ddh", ddh);
		params.put("maxdkje", maxdkje);
		params.put("mindkje", mindkje);
		params.put("state", state);

		
		
		List list = dkService.querydk(params);
		int count = dkService.getdkCount(params);
		result.put("data", list);	
		result.put("total", count);
		if (null!=page) {//新版本,传参
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
		}
		serialize(request,response,result);
		return null;
	}
}
